package five.autoview.activity;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;

import java.util.Timer;
import java.util.TimerTask;

import five.autoview.R;
import five.autoview.myview.BallMoveView;

public class WenZiActivity extends AppCompatActivity {
    private ImageView imageView;
    private BallMoveView ballMoveView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wen_zi);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });


        imageView = (ImageView)findViewById(R.id.image);
        Bitmap bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);

        //绘制文字
        Paint paint = new Paint();

        //加上抗锯齿标志
        paint.setAntiAlias(true);
        //设置实心画笔
        paint.setStyle(Paint.Style.FILL);
        paint.setTextAlign(Paint.Align.LEFT);

        int sp = 30;
        paint.setTextSize(sp);

        //设置倾斜
        paint.setTextSkewX(0.5f);
        paint.setUnderlineText(true);
        paint.setFakeBoldText(true);
        canvas.drawText("测试，使用，方便",10,300, paint);

        //绘制图形
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.YELLOW);
        paint.setStrokeWidth(30);
        paint.setStrokeJoin(Paint.Join.BEVEL);
        canvas.drawRect(new Rect(0,0,300,300), paint);
        canvas.drawOval(new RectF(30 ,30 ,400,400), paint);
        imageView.setImageBitmap(bitmap);


        ballMoveView = (BallMoveView) findViewById(R.id.ballview); new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                ballMoveView.postInvalidate();
            }
        }, 200, 50);
    }

}
